package org.cresource.user.conteoller;

import org.cresource.basic.exception.BusinessException;
import org.cresource.basic.util.AjaxResult;
import org.cresource.user.service.IVerifyCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 验证码
 */
@RequestMapping("/verifycode")
@RestController//返回数据格式为json是@Controller+@ResponseBod
public class VerifyCodeController {


    @Autowired
    private IVerifyCode verifyCode;

    //验证码获取
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> para) {
        try {
            verifyCode.sendSmsCode(para);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("稍后重试");
        }
    }
}